package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.MesProduceOrderSale;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.MesProduceOrderSaleDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-03-30 15:29:24
 */
public class MesProduceOrderSaleConverts {

    private static Logger LOG = LoggerFactory.getLogger(MesProduceOrderSaleConverts.class);

    public static List<MesProduceOrderSaleDTO> convert(List<MesProduceOrderSale> mesProduceOrderSaleList) {
        if (CollectionUtils.isEmpty(mesProduceOrderSaleList)) {
            return Collections.EMPTY_LIST;
        }

        List<MesProduceOrderSaleDTO> mesProduceOrderSaleListResult = Lists.newArrayList();
        for (MesProduceOrderSale mesProduceOrderSale : mesProduceOrderSaleList) {
            mesProduceOrderSaleListResult.add(convert(mesProduceOrderSale));
        }
        return mesProduceOrderSaleListResult;
    }

    public static MesProduceOrderSaleDTO convert(MesProduceOrderSale mesProduceOrderSale) {
        try {
            return BeanUtils.copy(mesProduceOrderSale, MesProduceOrderSaleDTO.class);
        } catch (Exception e) {
            LOG.error("MesProduceOrderSale到MesProduceOrderSaleDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesProduceOrderSale到MesProduceOrderSaleDTO转换失败", e);
        }
    }

    public static MesProduceOrderSale convert(MesProduceOrderSaleDTO mesProduceOrderSaleDTO) {
        try {
            return BeanUtils.copy(mesProduceOrderSaleDTO, MesProduceOrderSale.class);
        } catch (Exception e) {
            LOG.error("MesProduceOrderSaleDTO到MesProduceOrderSale转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesProduceOrderSaleDTO到MesProduceOrderSale转换失败", e);
        }
    }
}